import QtQuick 2.12
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.12
import HomeForm.Model 1.0

Page {
    property bool m_start: false

    title: qsTr("SIM DATA")

    // HomForm.ui.qml  Model
    HomeForm {
        id: homeForm
        onTerminal: {
            clearListViewModel()
            for (var i = 0; i < v.length; i++) {
                addListViewModel(v[i])
                terminalTitle.title = qsTr(
                            "TERMINAL    (") + v.length + qsTr(")")
            }
        }
    }

    //Terminal ListView JavaScript function
    function addListViewModel(name) {
        terminalListmodel.append({
                                     "name": name
                                 })
    }

    function clearListViewModel() {
        terminalListmodel.clear()
    }

    Column {
        id: column
        spacing: 10
        anchors.fill: parent
        anchors.rightMargin: 20
        anchors.leftMargin: 20
        anchors.bottomMargin: 20
        anchors.topMargin: 20

        Title {
            width: column.width
            title: qsTr("UPDATE FREQUENCY")
        }

        ComboBox {
            id: comboBox
            width: column.width / 2
            font.family: "Times New Roman"
            font.pixelSize: 12
            Material.accent: Material.DeepOrange

            textRole: "key"
            model: ListModel {
                id: comboBoxModel
                ListElement {
                    key: "50Hz"
                    value: 20
                }
                ListElement {
                    key: "25Hz"
                    value: 40
                }
                ListElement {
                    key: "1Hz"
                    value: 100
                }
            }
            onCurrentIndexChanged: homeForm.hz(comboBoxModel.get(comboBox.currentIndex).value)
        }

        Title {
            id: terminalTitle
            width: column.width
            title: qsTr("TERMINAL")
        }

        ListView {
            id: terminalListView
            width: column.width
            height: 50
            model: terminalListmodel
            delegate: Text {
                text: name
                font.family: "Times New Roman"
                font.pixelSize: 12
            }
        }
        ListModel {
            id: terminalListmodel
            ListElement {
                name: ""
            }
        }

        RoundButton {
            id: roundButton
            width: 80
            height: 80
            anchors.horizontalCenter: parent.horizontalCenter
            highlighted: true
            Material.accent: Material.LightGreen
            text: qsTr("START")
            font.bold: true
            font.pixelSize: 15
            font.family: "Times New Roman"
            onClicked: {
                if (m_start == false) {
                    homeForm.start()
                    Material.accent = Material.Red
                    text = qsTr("STOP")
                    comboBox.enabled = false
                    m_start = true
                } else {
                    clearListViewModel()
                    homeForm.stop()
                    Material.accent = Material.LightGreen
                    text = qsTr("START")
                    comboBox.enabled = true
                    m_start = false
                }
            }
        }
    }
}




/*##^## Designer {
    D{i:0;autoSize:true;height:480;width:640}
}
 ##^##*/
